home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
HYPERXCM
/
XCMDSTRI.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-22
|
3KB
|
113 lines
#include <string.h>
/*----------------------------------------------------------------
* This utility computes the length of a C-string.
*---------------------------------------------------------------*/
size_t strlen (str)
char *str;
{ char *temp;
temp = --str;
while (*(++temp)) ;
return ((size_t)(temp - str));
} /*- proc-end: strlen -*/
/*----------------------------------------------------------------
* This utility copies a C string from one place to another.
*---------------------------------------------------------------*/
char* strcpy (target, source)
char *target;
char *source;
{ char *dest;
dest = target;
while ((*target++ = *source++) != 0) ;
return (dest);
} /*- proc-end: strcpy -*/
/*----------------------------------------------------------------
* This utility copies a C string, limited length .
*---------------------------------------------------------------*/
char* strncpy (target, source, length)
char *target;
char *source;
size_t length;
{ char *dest;
dest = target;
while (length--)
{ if ((*target++ = *source++) != 0) continue;
while (length--) *target++ = '\0';
}
*target = '\0';
return (dest);
} /*- proc-end: strcpy -*/
/*------------------------------------------------------------------
* This utility concatenates two C-strings, source appended to target.
*-----------------------------------------------------------------*/
char* strcat (target, source)
char *target;
char *source;
{ char *dest;
dest = target;
--target;
while (*++target) ;
while ((*target++ = *source++) != 0) ;
return (dest);
} /*- proc-end: strcat -*/
/*------------------------------------------------------------------
* This utility concatenates two C-strings, limited length.
*-----------------------------------------------------------------*/
char* strncat (target, source, length)
char *target;
char *source;
size_t length;
{ char *dest;
dest = target;
--target;
while (*++target) ;
while (length--)
{ if ((*target++ = *source++) != 0) continue;
return (dest);
}
*target = '\0';
return (dest);
} /*- proc-end: strncat -*/
/*------------------------------------------------------------------
* This utility compares two C-strings, return < 0 > .
*-----------------------------------------------------------------*/
int strcmp (target, source)
char *target;
char *source;
{
while (*target == *source)
{ if (*target == 0) return (0);
++source; ++target;
}
return ((int)(*target-*source));
} /*- proc-end: strcmp -*/
/*------------------------------------------------------------------
* This utility compares two C-strings, limited length.
*-----------------------------------------------------------------*/
int strncmp (target, source, length)
char *target;
char *source;
size_t length;
{
while (length && (*target == *source))
{ if (*target == 0) return (0);
++source; ++target; --length;
}
if (length) return ((int)(*target-*source));
return (0);
} /*- proc-end: strncmp -*/